package com.adu.getpdf.controller;

import com.adu.getpdf.service.PdfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.FileNotFoundException;


@RestController
public class PdfController {

    @Autowired
    PdfService service;

    @GetMapping("/getPdf")
    public String getPdf() throws FileNotFoundException {
        // pdf模板地址
        String templatePath= ResourceUtils.getURL(ResourceUtils.CLASSPATH_URL_PREFIX +"templates/cainiaoadu.pdf").getPath();
        // 生成后pdf文件的地址
        String outPdfPath="D://测试.pdf";
        service.generatePdf(templatePath,outPdfPath);
        return "生成文件地址："+outPdfPath;
    }
}
